package common;

import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

import java.time.Duration;

/**
 * 配置浏览器驱动
 */
public class Utils {
    public WebDriver driver;
    public Utils(String url) {
        driver = setup();
        driver.get(url);
    }

    public WebDriver setup() {
        WebDriverManager.chromedriver().setup();
        // 对相关参数进行配置
        ChromeOptions options = new ChromeOptions();
        options.addArguments("--remote-allow-origins=*");
        // 创建驱动对象
        driver = new ChromeDriver(options);

        // 为所有查找添加隐式等待
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(2));

        return driver;
    }
}
